
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>注册</title>

    <!-- Bootstrap core CSS -->
    <link href="{{face}}/bootstrap337/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="http://v3.bootcss.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="http://v3.bootcss.com/examples/signin/signin.css" rel="stylesheet">


    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<div class="container">

    <form class="form-signin" >
        {{csrf_field()}}
        <h2 class="form-signin-heading">请注册</h2>
        <label for="name" class="sr-only">名字</label>
        <input type="text" name="user_name" class="form-control" placeholder="名字" required autofocus>
        <label for="inputEmail" class="sr-only">邮箱</label>
        <input type="email" name="user_email" class="form-control" placeholder="邮箱" required autofocus>
        <label for="inputPassword" class="sr-only">密码</label>
        <input type="password" name="user_password" class="form-control" placeholder="输入密码" required>
        <label class="sr-only">重复密码</label>
        <input type="password" name="password_confirmation" class="form-control" placeholder="重复输入密码" required>
        @include('face.layout.validatesError')



    </form>
    <button onclick="register()" class="btn btn-lg btn-primary btn-block">注册</button>
</div> <!-- /container -->
<script src="{{face}}/layui/jquery-3.1.1.js"></script>
<script src="{{face}}/layui/layui.js"></script>

<script type="text/javascript">
    layui.use('layer', function(){
        var layer = layui.layer;

    });
</script>

<script type="text/javascript">

//    function validationInfo(ary_errors) {
//        var str = "";
//
//        ary_errors.forEach(function (value) {
//
//            var ary_temp = value.split(":");
//            var v = ary_temp[1].replace('[').replace(']').replace('{').replace('}').replace("\"");
//
//            str=str+v+"<br/>";
//
//
//        });
//
//        return str;
//    }


    function register() {
        var myData = {
            'name' :$('input[name=user_name]').val(),
            'email':$('input[name=user_email]').val(),
            'password':$('input[name=user_password]').val(),
            'password_confirmation':$('input[name=password_confirmation]').val(),
            '_token':"{{csrf_token()}}"
        };

        var myUrl = "{{url('/register')}}";
        $.ajax({
            url:myUrl,
            type:'post',
            data:myData,
            dataTpye:'json',
            success:function(data,textStatus,jqXHR){
                console.log(data.msg);
//                console.log(textStatus);
//                console.log(jqXHR);
            },
//            error:function(responseText,textStatus){
//                console.log('错误');
////                console.log(res.email);
//                console.log(responseText);
////                console.log(textStatus);
//
//
////                console.log(res);
//            }
            error:function(xhr,textStatus){
                console.log('错误');
                var validation_info = "";
                var temp = JSON.parse(xhr.responseText);
                console.log(temp['name']);
                console.log(temp['email']);
                console.log(temp['password']);
               if(temp.name){
                   validation_info= validation_info+temp.name+"<br/>";
               }
               if(temp.email){
                   validation_info= validation_info+temp.email+"<br/>";
               }
               if(temp.password){
                   validation_info= validation_info+temp.password+"<br/>";
               }


                layer.open({
                    type: 1,
                    content: validation_info
//                    content: temp['name']+"<br/>"+temp['email']+"<br/>"+temp['password']
                });


//                ary_json.forEach(function (value) {
//                   console.log(value);
//                });


//                console.log(validation(temp));
//
//                console.log(temp);
//                console.log(temp['name']);
//                console.log(temp['email']);
//                console.log(temp['password']);


                console.log(textStatus);
            }
        });

    }
</script>
</body>
</html>

